package com.android.questions.ui.adapter;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.base.util.DQLog;
import com.android.questions.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hx.currency.data.model.Sign;

/**
 * FileName: SignAdapter
 * Author: admin
 * Date: 2022/1/18 13:24
 * Description:
 */
public class SignAdapter extends BaseQuickAdapter<Sign, BaseViewHolder> {

    private int todayPos = 0;
    private boolean todayState = false;

    public SignAdapter() {
        super(R.layout.item_sign);
    }

    @Override
    protected int getDefItemViewType(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Sign signEntity) {
        ImageView ivBg = baseViewHolder.getView(R.id.iv_bg);
        ImageView ivMask = baseViewHolder.getView(R.id.iv_mask);
//        ImageView ivQuan = baseViewHolder.getView(R.id.iv_quan);
        TextView tvDate = baseViewHolder.getView(R.id.tv_date);
        ImageView ivResult = baseViewHolder.getView(R.id.iv_result);
        FrameLayout flAmount = baseViewHolder.getView(R.id.fl_amount);
        ImageView ivTextBg = baseViewHolder.getView(R.id.iv_text_bg);
        TextView tvAmount = baseViewHolder.getView(R.id.tv_amount);

        double rs = signEntity.getRs();
        String str = "第" + signEntity.getDays() + "天";
        if (rs >= 1000) {
            str = "超级大奖";
        }
        tvDate.setText(str);

        tvAmount.setText("x " + (int) rs);

        if (signEntity.getSt() != 0) {//已签到
            ivMask.setVisibility(View.VISIBLE);
            ivResult.setVisibility(View.VISIBLE);
            flAmount.setVisibility(View.INVISIBLE);
        } else {//未签到
            ivMask.setVisibility(View.GONE);
            ivResult.setVisibility(View.GONE);

            flAmount.setVisibility(View.VISIBLE);
            ivBg.setImageResource(R.drawable.icon_sign_bg_2);
            ivTextBg.setImageResource(R.drawable.icon_sign_text_bg_2);
        }

        if (this.todayState) {
            DQLog.e("当天已经签到过了");
            return;
        }

        if (getItemPosition(signEntity) == todayPos) {//签到当天，还未签到的
            ivMask.setVisibility(View.GONE);
            ivResult.setVisibility(View.GONE);
            ivBg.setImageResource(R.drawable.icon_sign_bg_1);
            ivTextBg.setImageResource(R.drawable.icon_sign_text_bg_1);
        }
    }

    public void setTodayPos(int dayPos) {
        this.todayPos = dayPos;
    }

    public void setTodayState(boolean state) {
        this.todayState = state;
    }
}